/** 
 * 自定义签到
 * */
 
 
 
 
 
 // 获取签到
 function getSignOne(){
 	// 获取小时
 	var hcurr = getHourCurr();
 	var resList = getSignCache();
 	var list = resList.list;
 	var hour = 0;
 	for (var i=0;i<list.length;i++) {
 		if (list[i].signHour==hcurr.hour) { 
 			hour = list[i].signHour; 
 		}
 	}
 	// mui.alert('hour'+hour); return
 	var h = "", hnext = 0;
 	if (hour) {
 		hnext = hour==12 ? "次日" : hour*1+1;
 		h = hour+"点已签到<br>"+hnext+"点再签到";
 		mui("#signDiv")[0].innerHTML = h;
 	} else {
 		h = hcurr.hour+"点可以签到";
 		mui("#signDiv")[0].innerHTML = h;
 	}
 }
 // 定位测试
 function setSign(){
 	mui.plusReady(function() {
 		plus.geolocation.getCurrentPosition(
 			translatePoint,
 			function(e){
 				mui.toast("异常:" + e.message);
 	        }
 		);
 	});
 }
 // 获取定位坐标
 function translatePoint(position){
     var currentLon = position.coords.longitude;
     var currentLat = position.coords.latitude;
     // mui.toast(currentLon, currentLat);
 	// 书写自己的逻辑
 	setUserSign(currentLon, currentLat);
 }
 // 同步用户坐标
 function setUserSign(lon, lat){
 	// 系统参数
 	var sys = getSys();
 	var domain = sys.domain + '/app/reward/sign/add';
 	// 用户信息
 	var userInfo = cacheGet(userInfoKey);
 	var uid = userInfo ? userInfo.uid : 0;
 	mui.ajax(domain,{
 		data:{
 			appAccess: sys.appAccess,
 			uid: uid,
 			lon: lon,
 			lat: lat
 		},
 		dataType:'json', //服务器返回json格式数据
 		type:'post', //HTTP请求类型
 		timeout:10000, //超时时间设置为10秒
 		headers:{
 			'Content-Type':'application/x-www-form-urlencoded',
 		}, 
 		success:function(res){
 			var hour = getHourCurr();
 			if (res.code==-1) {
 				mui.toast('需要更新系统参数',{ 
 					duration:'short', type:'div',
 				});
 				setTimeout(function(){
 					setSys();
 					jumpToIndex();
 				},500);
 			} else if (res.code!=0) {
 				mui.toast(hour.hour+'点已签到');
 				return
 			}
 			mui.toast('签到成功',{ 
 				duration:'short', type:'div',
 			});
 			var signId = res.data.lastId;
 			var signDate = res.data.createTime;
 			var one = {
 				signId:signId,
 				signLon:lon,
 				signLat:lat,
 				signYmdh:hour.ymdh,
 				signDate:signDate,
 				signHour:hour.hour
 			};
 			// 更新缓存
 			setSignCache(one);
 			// 刷新页面
 			setTimeout(function(){
 				jumpToRewardSignAdd();
 			}, 1000);
 		},
 		error:function(xhr,type,errorThrown){
 			mui.toast('网络错误！',{ 
 				duration:'short', type:'div',
 			});
 		}
 	});
 }
 // 获取当前小时
 function getHourCurr(){
 	var day = new Date();
 	var d = day.getFullYear().toString() + (day.getMonth()+1).toString() + day.getDate().toString();
 	var y = day.getFullYear();
 	var m = day.getMonth()+1;
 	var d = day.getDate();
 	var h = day.getHours();
 	if (m < 10) { m = '0'+m; }
 	if (h < 10) { h = '0'+h; }
 	var ymdh = y + m + d + h;
 	return {
 		ymdh:ymdh,
 		hour:h
 	};
 }
 // 获取数据缓存
 function getSignCache(){
 	var resList = cacheGet(rewardSignList);
 	if (!resList) {
 		var list = new Array(), //数据数组
 			idstring = ''; //ID字符串集合
 		return {
 			// 数据数组
 			list: list,
 			// 历史ID集合
 			idstr: idstring
 		};
 	}
 	return resList;
 }
 /** 
  * 设置数据缓存
  * one 新数据一个
  * */
 function setSignCache(one){
 	var resList = getSignCache();
 	var list = resList.list,  //数据数组
 		idstring = resList.idstr; //历史ID字符串集合
 	if (list.length==0) {
 		idstring = one.signId;
 	} else {
 		idstring = idstring+','+one.signId;
 	}
 	list[list.length] = one;
 	var signNew = {
 		// 数据数组
 		list: list,
 		// 历史ID字符串集合
 		idstr: idstring,
 	};
 	cacheSet(rewardSignList, signNew);
 }